package com.qf.sys.controller;

import com.qf.common.R;
import com.qf.sys.param.LoginParam;
import com.qf.sys.service.SysUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * @author zdl
 * @date 2025/2/26
 */
@RestController
@RequestMapping("/sys/user")
public class SysUserController {
    @Resource
    private SysUserService sysUserService;

    @PostMapping("/login")
    public R<?> loginSysUserByUserNameAndPassword(@RequestBody LoginParam loginParam, HttpSession session) {
        String token = sysUserService.loginByUserNameAndPassword(loginParam);
        session.setAttribute("token", token);
        return R.ok(token);
    }

    @GetMapping("/info")
    public R<?> info(HttpSession session) {
        String token = (String) session.getAttribute("token");
        return R.ok(token);
    }

    @PostMapping("/logout")
    public R<String> logout(HttpSession session) {
        session.removeAttribute("sysUser");
        return R.ok("退出登录");
    }

    @PostMapping("/sendMailCode")
    public R<String > sendMailCode(String email) {
        String s = sysUserService.sendMailCode(email);
        return R.ok(s);
    }
}
